<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
</head>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
        <a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
            <span class="aui-iconfont aui-icon-left"></span>
        </a>
        <div class="aui-title" id="title">
            维修保养任务执行
        </div>
    </header>
    <div class="aui-content aui-margin-b-15" style="margin-top:50px;">
        <ul class="aui-list aui-form-list">
            <li class="aui-list-item">
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label" style="width:30%;font-size: 14px;">起始时间</div>
                    <div class="aui-list-item-input" style="float:left;width: 70%;">
                        <input type="text" id="actualBeginDate" onclick="showTime();">
                    </div>
                </div>
            </li>
            <li class="aui-list-item" >
                <div class="aui-list-item-inner">
                    <div class="aui-list-item-label" style="width:30%;font-size: 14px;">截止时间</div>
                    <div class="aui-list-item-input" style="float:left;width: 70%;">
                        <input type="text" id="actualEndDate" onclick="showTime2();">
                    </div>
                </div>
            </li>

        </ul>
        <div style="width:100%;margin-top:2%;"></div>
        <div class="aui-btn aui-btn-info" style="margin-left:10%;width:30%;" onclick="doSearch()">查询</div>
        <div class="aui-btn aui-btn-info" style="width:30%;margin-left:10%;" onclick="goPage()">任务执行</div>
        <div style="background-color:white; height: 100%;width: 100%;margin-top:2%;margin-bottom:50px;">
            <table class="table" style='width:100%;' id="table">
                <thead>
                    <tr style="text-align: center;background-color: #DCE9F2;color: #467aa7;font-size: 8px;font-weight: bold;">
                        <td algin='center'></td>
                        <td algin='center'>任务单号</td>
                        <td algin='center'>设备编码</td>
                        <td algin='center'>设备名称</td>
                        <td algin='center'>开始时间</td>
                        <td algin='center'>任务状态</td>
                        <td algin='center' style='display:none;'>任务单ID</td>
                        <td algin='center' style='display:none;'>设备ID</td>
                        <td algin='center' style='display:none;'>任务单结果</td>
                    </tr>
                </thead>
                <tbody id="tbodyHtml">
                </tbody>
            </table>
        </div>
    </div>
    <footer class="aui-bar aui-bar-tab" id="footer">
        <div class="aui-bar-tab-item" tapmode id="scan" onclick="doScan()">
            <i class="aui-iconfont aui-icon-scan aui-text-epblue" style="font-size: 1.8rem"></i>
        </div>
    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">
    //光标所在id
    var idSelector = "";
    var sysid = ""; //盘点单据GID
    var billCode = "";//盘点单号
    var type ="";
    var d=new Date()
    var day=d.getDate()    
    var month=d.getMonth() + 1 < 10 ? "0" + (d.getMonth() + 1) : d.getMonth() + 1;
    var year=d.getFullYear()
    var shijian=year + "-" + month + "-" + day + " 00:00:00"; 
    var shijiannext = year + "-" + month + "-" + day + " 23:59:59"; 
    apiready = function () {
        $("#actualBeginDate").val(shijian);
        // $("#actualEndDate").val(getNextDate(shijian,+1));
        $("#actualEndDate").val(shijiannext);
        
        doSearch();
    }
    function getNextDate(date, day) { 
    　　var dd = new Date(date);
    　　dd.setDate(dd.getDate() + day);
    　　var y = dd.getFullYear();
    　　var m = dd.getMonth() + 1 < 10 ? "0" + (dd.getMonth() + 1) : dd.getMonth() + 1;
    　　var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate();
    　　return y + "-" + m + "-" + d;
    };
    // 获取光标所在组件的id
    function getIdSelector() {
        var e = event || window.event;
        var el = e.srcElement || e.target;
        if (el.id == "billCode") {
            $("#billCode").select();
        } else if (el.id == "rsCode") {
            $("#rsCode").select();
        }
        idSelector = el.id;
        $("#" + el.id).select();
    }
    function showTime() {
		var moduleTimer = api.require('moduleTimer');
		moduleTimer.showTimer({
			startTime: '2000-01-1 00:00',//可选择的起始时间
			endTime: '2099-12-31 23:59',//可选择的结束时间
			timeFormat: 'yyyy-MM-dd HH:mm:ss',//返回的时间格式，如果不传默认是yyyy-MM-dd HH:mm:ss
			selColor: '#079962'//选中的颜色值
		}, function (ret, err) {
			var actualBeginDate = ret;
			var text = document.getElementById("actualBeginDate");
			text.value = actualBeginDate;
		});
	}

	function showTime2() {
		var moduleTimer = api.require('moduleTimer');
		moduleTimer.showTimer({
			startTime: '2000-01-1 00:00',//可选择的起始时间
			endTime: '2099-12-31 23:59',//可选择的结束时间
			timeFormat: 'yyyy-MM-dd HH:mm:ss',//返回的时间格式，如果不传默认是yyyy-MM-dd HH:mm:ss
			selColor: '#079962'//选中的颜色值
		}, function (ret, err) {
			var actualEndDate = ret;
			var text = document.getElementById("actualEndDate");
			text.value = actualEndDate;
		});
	}
    //查询
    function doSearch() {

        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/executionSelectEquipTask";
        //获取菜单配置参数
        var query = api.pageParam.query;
		if(query.type!=undefined && query.type!=null && query.type!=""){
			type = query.type;
        }
        //实际开始时间
        var actualBeginDate = document.getElementById("actualBeginDate").value;
        //实际结束时间
        var actualEndDate = document.getElementById("actualEndDate").value;

        var data = {
            values: {
                type: type,
                actualBeginDate: actualBeginDate,
                actualEndDate: actualEndDate,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 300,
            returnAll: false,
            data: data
        }, function(ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    var list = eval(myobj.list);
                    var html = "";
                    for (var i = 0; i < list.length; i++) {
                        html += "<tr style='text-align: center;color: black;font-size: 12px;background-color: #F5F5F5;'>";
                        html += "<td style='width:40px;'><input name='sub' type='checkbox' /></td>";
                        html += "<td name='taskcode'>" + list[i].taskcode + "</td>";
                        html += "<td name='equipmentno'>" + list[i].equipmentno + "</td>";
                        html += "<td name='equipmentname'>" + list[i].equipmentname + "</td>";
                        html += "<td name='begindate'>" + list[i].begindate + "</td>";
                        html += "<td name='status'>" + list[i].status + "</td>";
                        html += "<td name='id' style='display:none;'>" + list[i].id + "</td>"; //style='display:none;'
                        html += "<td name='equipid' style='display:none;'>" + list[i].equipid + "</td>";
                        html += "<td name='taskresult' style='display:none;'>" + list[i].taskresult + "</td>";
                        html += "</tr>";
                    }
                    $api.html($api.byId("tbodyHtml"), html);

                    //失败
                } else if (myobj.code == "1") {

                    //清空表格数据
                    $api.html($api.byId("tbodyHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            }
        });
    }
    function goPage(){
        //选中数据
        var check = $("input[type='checkbox']:checked"); //在table中找input下类型为checkbox属性为选中状态的数据
        var count = 0;
        check.each(function() {
            count++;
        });

        //选中行为0
        if (count == 0) {
            api.toast({
                msg: '请选择数据！',
                duration: 3000
            });
            return;
        }
        //选中行不为1
        if (count > 1) {
            api.toast({
                msg: '只能选择一条数据！',
                duration: 3000
            });
            return;
        }
        check.each(function() { //遍历
            var row = $(this).parent("td").parent("tr");
            var taskcode = row.find("[name='taskcode']").html();
            var equipmentno = row.find("[name='equipmentno']").html();
            var equipmentname = row.find("[name='equipmentname']").html();
            var id = row.find("[name='id']").html();
            var equipid = row.find("[name='equipid']").html();
            var taskresult = row.find("[name='taskresult']").html();

            var url;
            var name = 'uemChkTask-execution';
            api.openWin({
                        name: 'uemChkTask-createEquipTask-tnk',
                        url: 'uemChkTask-createEquipTask-tnk.html',
                        pageParam: {
                            url: url,
                            name: name,
                            SRequipCode: equipmentno,
                            id :id,
                            equipId :equipid,
                            equipCode :equipmentno,
                            equipName :equipmentname,
                            taskResult :taskresult,
                            code : taskcode,
                            type : type
                        }
                    });
        });
    }
    
    function doSubmit(){
        doSearch()
    }
    //返回按钮
	function closeWin() {
		api.closeWin({});
	}
</script>

</html>